package com.sync.hkmjsyncdata;

import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.net.ntp.NTPUDPClient;
import org.apache.commons.net.ntp.TimeInfo;
import org.apache.commons.net.ntp.TimeStamp;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

public class Test {


//    public static void main(String[] args) {
//
//
//        try (
//                ZipArchiveInputStream zipIn = new ZipArchiveInputStream(new FileInputStream("D:\\sa.zip"), "GBK", true, true)
//        ) {
//
//            ArchiveEntry zipEntry = null;
//            String fileName="";
//            while ((zipEntry = zipIn.getNextEntry()) != null) {
//                if (!zipEntry.isDirectory()) {
//
//                    if(ObjectUtils.isNotEmpty(fileName)&&zipEntry.getName().startsWith(fileName)){
//                        System.out.println("不解析");
//                        continue;
//                    }else {
//                        fileName="";
//                    }
//                    System.out.println("解析文件:"+zipEntry.getName());
//
//                }else {
//                    if(ObjectUtils.isNotEmpty(fileName)&&zipEntry.getName().startsWith(fileName)){
//                        System.out.println("不解析");
//                        continue;
//                    }else {
//                        fileName="";
//                    }
//                    String names []=zipEntry.getName().split("/");
//                    System.out.println(names[names.length-1]);
//                    String items []=names[names.length-1].split("-");
//                    System.out.println(items.length);
//                    System.out.println("解析目录:"+zipEntry.getName());
//                    if(items.length==5){
//                        fileName=zipEntry.getName();
//
//                    }
//
//                }
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//    }

    public static void main(String[] args) throws IOException {

        try {

            NTPUDPClient timeClient = new NTPUDPClient();

            String timeServerUrl = "10.191.64.40";

            InetAddress timeServerAddress = InetAddress.getByName(timeServerUrl);

            TimeInfo timeInfo = timeClient.getTime(timeServerAddress);

            TimeStamp timeStamp = timeInfo.getMessage().getTransmitTimeStamp();

            Date date = timeStamp.getDate();

            System.out.println(date);

            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

            System.out.println(dateFormat.format(date));

        } catch (UnknownHostException e) {

            e.printStackTrace();

        }

    }

}
